import keyboard
import pyautogui
import pyperclip
from PyQt5 import QtCore, QtWidgets
import time
import os

"""
不能直接使用ctrl+c和ctrl+v文件拷贝至微信联系人的发送信息栏中原因未知
"""

class WeChat():
    @staticmethod
    def copy_to_wechat(path):
        app = QtWidgets.QApplication([])
        data = QtCore.QMimeData()  # 创建一个QMimeData对象存储数据
        url = QtCore.QUrl.fromLocalFile(path)
        data.setUrls([url])  # 将文件路径复制到QMimeData容器中
        app.clipboard().setMimeData(data)

    @classmethod
    def wechat_send(cls, path, name):
        pyautogui.hotkey('ctrl', 'alt', 'w')
        time.sleep(0.5)
        pyautogui.hotkey('ctrl', 'f')
        time.sleep(0.5)
        pyperclip.copy(name)
        pyautogui.hotkey('ctrl', 'v')
        time.sleep(0.5)
        keyboard.press_and_release('enter')
        time.sleep(0.5)
        cls.copy_to_wechat(path)
        time.sleep(0.5)
        pyautogui.hotkey('ctrl', 'v')
        time.sleep(0.5)
        keyboard.press_and_release('enter')
        time.sleep(0.5)
        pyautogui.hotkey('ctrl', 'alt', 'w')
        os.remove(path)

if __name__ == '__main__':
    wechat = WeChat()
    wechat.wechat_send('your_path', 'your_WeChat_send_name')
